package week01

// 1109. 航班预订统计
// https://leetcode-cn.com/problems/corporate-flight-bookings/

// 差分
// 前缀和

func corpFlightBookings(bookings [][]int, n int) []int {
	var ans = make([]int, n+2)
	for i := 1; i <= len(bookings); i++ {
		var booking = bookings[i-1]
		ans[booking[0]] += booking[2]
		ans[booking[1]+1] -= booking[2]
	}
	var sums = make([]int, n+2)
	for i := 1; i < len(ans); i++ {
		sums[i] = sums[i-1] + ans[i]
		sums[i-1] = sums[i]
	}
	return sums[:len(sums)-2]
}